using System.Collections;
using System.Collections.Generic;
using Gp.Scripts.GUI;

namespace Gp.Scripts.Core
{
    /// <summary>
    /// Class representing a human player.
    /// </summary>
    public class HumanPlayer : BattlePlayer
    {
        public override void Play()
        {
            Global.Get<BattleSystem>().BattleSettle.GameState = new GameStateWaitForInput();
        }


        public override void ContinuePlay(Ability ability = null)
        {
            var system   = Global.Get<BattleSystem>();
            var cellGrid = system.BattleSettle;

            if (system.CurrentUnit == null) return;

            // 如果当前游戏回合状态为 技能选择状态，并且为同一单位发起的技能选择状态，则仅更新技能选择
            if (cellGrid.GameState is not GameStateUnitSelect abilitySelected)
            {
                cellGrid.GameState = new GameStateUnitSelect(system.CurrentUnit);
            }
            else
            {
                abilitySelected.UpdateAbility(ability as SkillEntity);
            }
        }

        public override IEnumerator ResolveReaction<T>(List<BaseReactionEntity> reactions, T args)
        {
            // 渲染窗口
            yield return Global.Get<GridBattleGUISystem>().ReactionSelectWindow(reactions, args);
        }

        public override IEnumerator ResolveOption(SkillEntity skill, IEnumerable<OptionItem> args)
        {
            return Global.Get<GridBattleGUISystem>().OptionWindow(args);
        }
    }
}